import pprint
import time
import sys

sys.path.append("../")  # noqa
import datetime

import pymongo
from bson import ObjectId
from pymongo import MongoClient
from config import col_okr, col_register, col_alumni
from config import client
from config import settings


register = col_register
alumni = col_alumni


def task_update_alumni_completion_score(person_id=None):
    """计算人才的完整度"""
    if person_id:
        person_id = ObjectId(person_id)
    person_doc = alumni.find_one(
        {"_id": person_id, "is_deleted": {"$ne": True}},
        {
            "name": 1,
            "name_zh": 1,
            "phone": 1,
            "identify_id": 1,
            "job_title": 1,
            "cur_institution_name": 1,
            "identify_photo": 1,
        },
    )
    flag = 0
    if not person_doc:
        return

    if (
        (person_doc.get("name") or person_doc.get("name_zh"))
        and person_doc.get("phone")
        and person_doc.get("identify_id")
        and person_doc.get("job_title")
        and person_doc.get("cur_institution_name")
        and person_doc.get("identify_photo")
    ):
        flag = 1

    data = register.update_many({"person_id": person_id, 'is_attended': True}, {"$set": {"refs_participants": flag}})

    return data.modified_count


if __name__ == "__main__":
    t = time.time()
    task_update_alumni_completion_score("630df4bba29c1327a1d75766")
    print(time.time() - t)
